const { DataTypes } = require('sequelize')
const seq = require('../utils/seq')
const moment = require('moment')

/**定时任务
 *id UUID
  任务名称：name string
  调用目标字符串：invoke_target string
  cron执行表达式：cron_expression string
  通知内容：content text
  通知邮箱：email string
  状态：status boolean
  用户id：uid UUID
  创建时间：ctime String
  更新时间：mtime String
 */

module.exports = seq.define('task', {
  id: {
    type: DataTypes.UUID,
    primaryKey: true,
    allowNull: false,
    defaultValue: DataTypes.UUIDV4,
    comment: '定时任务id'
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '任务名称'
  },
  invoke_target: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '调用目标字符串'
  },
  cron_expression: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: 'cron执行表达式'
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: true,
    defaultValue: '',
    comment: '通知内容'
  },
  email: {
    type: DataTypes.STRING,
    allowNull: true,
    defaultValue: '',
    comment: '通知邮箱'
  },
  uid: {
    type: DataTypes.UUID,
    allowNull: false,
    comment: '用户表外键'
  },
  status: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: true,
    comment: '状态（默认启用）'
  },
  ctime: {
    type: DataTypes.STRING,
    defaultValue: moment().format('YYYY-MM-DD HH:mm:ss'),
    comment: '创建时间'
  },
  mtime: {
    type: DataTypes.STRING,
    defaultValue: moment().format('YYYY-MM-DD HH:mm:ss'),
    comment: '更改时间'
  }
})